package com.modern.devtools.model;

import javafx.beans.property.*;

import java.util.Objects;

/**
 * Represents a server in the system.
 * Using JavaFX Properties for UI data binding.
 */
public class Server {
    
    private final StringProperty id = new SimpleStringProperty();
    private final StringProperty name = new SimpleStringProperty();
    private final StringProperty host = new SimpleStringProperty();
    private final IntegerProperty port = new SimpleIntegerProperty(22);
    private final StringProperty username = new SimpleStringProperty();
    private final StringProperty password = new SimpleStringProperty(); // Should be stored securely
    private final StringProperty privateKeyPath = new SimpleStringProperty();
    private final StringProperty passphrase = new SimpleStringProperty(); // For encrypted private keys
    private final StringProperty group = new SimpleStringProperty(); // For grouping servers by project/environment
    
    // Constructor
    public Server(String id, String name, String host, int port, String username) {
        setId(id);
        setName(name);
        setHost(host);
        setPort(port);
        setUsername(username);
    }
    
    // Getters and Setters
    public String getId() {
        return id.get();
    }
    
    public void setId(String id) {
        this.id.set(id);
    }
    
    public StringProperty idProperty() {
        return id;
    }
    
    public String getName() {
        return name.get();
    }
    
    public void setName(String name) {
        this.name.set(name);
    }
    
    public StringProperty nameProperty() {
        return name;
    }
    
    public String getHost() {
        return host.get();
    }
    
    public void setHost(String host) {
        this.host.set(host);
    }
    
    public StringProperty hostProperty() {
        return host;
    }
    
    public int getPort() {
        return port.get();
    }
    
    public void setPort(int port) {
        this.port.set(port);
    }
    
    public IntegerProperty portProperty() {
        return port;
    }
    
    public String getUsername() {
        return username.get();
    }
    
    public void setUsername(String username) {
        this.username.set(username);
    }
    
    public StringProperty usernameProperty() {
        return username;
    }
    
    public String getPassword() {
        return password.get();
    }
    
    public void setPassword(String password) {
        this.password.set(password);
    }
    
    public StringProperty passwordProperty() {
        return password;
    }
    
    public String getPrivateKeyPath() {
        return privateKeyPath.get();
    }
    
    public void setPrivateKeyPath(String privateKeyPath) {
        this.privateKeyPath.set(privateKeyPath);
    }
    
    public StringProperty privateKeyPathProperty() {
        return privateKeyPath;
    }
    
    public String getPassphrase() {
        return passphrase.get();
    }
    
    public void setPassphrase(String passphrase) {
        this.passphrase.set(passphrase);
    }
    
    public StringProperty passphraseProperty() {
        return passphrase;
    }
    
    public String getGroup() {
        return group.get();
    }
    
    public void setGroup(String group) {
        this.group.set(group);
    }
    
    public StringProperty groupProperty() {
        return group;
    }
    
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Server server = (Server) o;
        return Objects.equals(id.get(), server.id.get());
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(id.get());
    }
    
    @Override
    public String toString() {
        return "Server{" +
                "id='" + id.get() + "'" +
                ", name='" + name.get() + "'" +
                ", host='" + host.get() + "'" +
                ", port=" + port.get() +
                ", username='" + username.get() + "'" +
                ", group='" + group.get() + "'" +
                '}';
    }
}
